/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 combat_flinch.cpp

	$Header: /heroes4/three_head_attack.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "combat_flinch.h"

#include "battlefield.h"
#include "combat_actor_action.h"
#include "combat_creature.h"


// ------------------------------------------------------------
// play an appropriate flinch animation for a list of creatures
// ------------------------------------------------------------
void t_combat_flinch::add( t_attackable_object& defender, bool robe_only )
{
	t_flincher flincher;
	flincher.flincher = defender.get_object();
	flincher.robe_only = robe_only;
	m_targets.push_back( flincher );
}

// ------------------------------------------------------------
// play an appropriate flinch animation for a list of creatures
// ------------------------------------------------------------
void t_combat_flinch::operator()( t_combat_creature& creature )
{
	t_flincher_list::iterator		index = m_targets.begin();
	t_flincher_list::iterator		end   = m_targets.end();
	t_attackable_object*			defender;
	t_battlefield&					battlefield = creature.get_battlefield();

	for (; index != end; index++)
	{
		defender = index->flincher.get()->get_attackable_object();
		
		if ( index->robe_only )
		{
			defender->check_guardian_robe();
		}
		else
		{
			if ( !defender->check_guardian_robe() )
				defender->flinch( m_attacker, m_message );

			defender->apply_damage( battlefield, true );
		}
	}
}
